import {handler, view, BondViewGroup} from "adajs";
import NewsService from "./state.js";
import Bar from "../../../controls/bar";
import NewsDetail from "../../../controls/detail/news";
import {getQueryInfo} from "./../../../lib/helper";
import Reading from "../../../controls/reading";

@view({
    className: "news",
    template: "./template.html",
    style: "./style.scss",
    dataset: {
        service: NewsService
    }
})
class News extends BondViewGroup {
    tags() {
        return {
            bar: Bar,
            detail: NewsDetail
        }
    }

    onready() {
        let r = getQueryInfo();
        if (r.id) {
            this.commit("load", r.id);
        }
    }

    @handler("bar-listen")
    listen() {
        let info = this.getChildrenByType(NewsDetail)[0].getCurrentState().newsInfo;
        this.addChild(Reading, {
            parameter: {
                info: info.title + "。" + info.content
            }
        });
    }
}

export default News;